﻿using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp
{
    public class ZipHelper
    {
        public static void ZipDirectory(string sourceDirectory, string zipFilePath)
        {
            // 如果目标zip文件已存在，则删除
            if (File.Exists(zipFilePath))
            {
                File.Delete(zipFilePath);
            }
            // 压缩文件夹
            ZipFile.CreateFromDirectory(sourceDirectory, zipFilePath);
        }

        public static void UnzipToDirectory(string zipFilePath, string extractDirectory)
        {
            // 如果目标解压目录不存在，则创建
            if (!Directory.Exists(extractDirectory))
            {
                Directory.CreateDirectory(extractDirectory);
            }
            // 解压缩
            ZipFile.ExtractToDirectory(zipFilePath, extractDirectory);
        }
    }
}
